package cn.swust.designpatternlearningplatform.dao;

import cn.swust.designpatternlearningplatform.domain.entity.KnowledgePoint;
import cn.swust.designpatternlearningplatform.domain.entity.TopicKnowledgeCorrelation;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import java.util.Collection;
import java.util.List;
import java.util.Set;

@Mapper
public interface TopicKnowledgeCorrelationDao {
    /**
     * 获取与知识点相关联的题目的id
     *
     * @param pointId
     * @return java.util.List<java.lang.Integer>
     * @author Tang
     * @date 2023/4/20 19:40
     **/
    @Select("SELECT topic_id " +
            "FROM topic_knowledge_correlation " +
            "WHERE point_id = #{id}")
    List<Integer> getPointLinkedWithTopic(@Param("id") Integer pointId);

    /**
     * 添加题目和知识点的关系
     *
     * @param topicKnowledgeCorrelation
     * @return java.lang.Integer
     * @author Tang
     * @date 2023/5/13 15:56
     **/
    @Insert("INSERT INTO " +
            "topic_knowledge_correlation(topic_id, point_id) " +
            "VALUES(${connect.topicId},${connect.pointId}) ")
    Integer addTopicKnowledgeCorrelation(@Param("connect") TopicKnowledgeCorrelation topicKnowledgeCorrelation);

    /**
     * @param topicId:
     * @return List<Integer>
     * @author wang
     * description 获取与题目相关的知识点
     * date 2023/5/28 16:36
     */
    @Select("SELECT point_id " +
            "FROM topic_knowledge_correlation " +
            "WHERE topic_id = ${id}")
    List<Integer> getPointIdByTopicId(@Param("id") Integer topicId);

    /**
     * 获取与题目相关联的知识点的id
     *
     * @param topicId
     * @return java.util.List<java.lang.Integer>
     * @author Tang
     * @date 2023/5/17 10:57
     **/
    @Select("SELECT point_id " +
            "FROM topic_knowledge_correlation " +
            "WHERE topic_id = #{id}")
    List<Integer> selectTopicLinkedWithPoint(@Param("id") Integer topicId);

    /**
     * 添加题目和知识点的关系
     *
     * @param topicKnowledgeCorrelation
     * @return java.lang.Integer
     * @author Tang
     * @date 2023/5/13 15:56
     **/
    @Insert("INSERT INTO " +
            "topic_knowledge_correlation(topic_id, point_id) " +
            "VALUES(#{connect.topicId},#{connect.pointId}) ")
    Integer insertTopicKnowledgeCorrelation(@Param("connect") TopicKnowledgeCorrelation topicKnowledgeCorrelation);

    /**
     * 获取与知识点相关联的题目的id
     *
     * @param pointId
     * @return java.util.List<java.lang.Integer>
     * @author Tang
     * @date 2023/4/20 19:40
     **/
    @Select("SELECT topic_id " +
            "FROM topic_knowledge_correlation " +
            "WHERE point_id = #{id}")
    List<Integer> selectPointLinkedWithTopic(@Param("id") Integer pointId);

    /**
     * 查询相关联的题目的数量
     *
     * @param pointId
     * @return java.lang.Integer
     * @author Tang
     * @date 2023/7/10 13:20
     **/
    @Select("SELECT COUNT(*) " +
            "FROM topic_knowledge_correlation " +
            "WHERE point_id = #{id}")
    Integer selectPointLinkedWithTopicNum(@Param("id") Integer pointId);

    /**
     * 查询相关联的题目的数量
     *
     * @param pointId
     * @return java.lang.Integer
     * @author Tang
     * @date 2023/7/10 13:20
     **/
    Integer selectPointLinkedWithTopicNumBatch(@Param("ids") List<Integer> pointId);

    /**
     * 批量插入
     *
     * @param entity
     * @return void
     * @author Tang
     * @date 2023/7/22 10:36
     **/
    void insertBatch(@Param("entity") List<TopicKnowledgeCorrelation> entity);

    /**
     * 根据id删除题目的知识点
     *
     * @param topicId
     * @param pointId
     * @return void
     * @author Tang
     * @date 2023/7/22 10:37
     **/
    void deleteById(@Param("topicId") Integer topicId, @Param("pointId") Integer pointId);

    /**
     * 根据topicId删除题目的知识点
     *
     * @param topicId
     * @return void
     * @author Tang
     * @date 2023/7/22 10:37
     **/
    void deleteAllByTopicId(@Param("topicId") Integer topicId);

    List<TopicKnowledgeCorrelation> selectPointsByTopicIds(@Param("topicIds") Collection<Integer> topicIds);

    /**
     * 批量获取与知识点相关联的题目的id
     *
     * @param pointIds
     * @return java.util.List<java.lang.Integer>
     * @author Tang
     * @date 2023/4/20 19:40
     **/
    List<Integer> selectPointLinkedWithTopicBatch(@Param("ids") List<Integer> pointIds,
                                             @Param("current") Integer currentPage,
                                             @Param("pageSize") Integer pageSize);
}
